package main

import "fmt"

//使用嵌套结构体来模拟封装性
type Struct_people struct {
	Name string
	Age int
}

type Struct_puple struct {
	Struct_people
	Parent string
}

type Struct_graduate struct{
	Struct_people
	Friend string
}

func (people *Struct_people) Eat(){
	fmt.Println("eat")
}

func (piple *Struct_puple) GetParent(){
	fmt.Println(piple.Parent)
}

func (graduate *Struct_graduate) GetFriend(){
	fmt.Println(graduate.Friend)
}

func main() {
	puple := &Struct_puple{}
	puple.Struct_people.Name = "ha"
	puple.Struct_people.Age = 11
	puple.Parent = "henduo"
	puple.Eat()
	puple.GetParent()

	graduate := &Struct_graduate{
		Friend:"good",
	}
	//嵌套结构的简化写法，如果在当前结构体中不包含此属性
	//在嵌套的结构体中查找
	//注意此种方法只可以在匿名嵌套使用，如果给嵌套的结构体命名则必须显式访问
	graduate.Name = "wuwu"
	graduate.Age = 20
	graduate.Eat()
	graduate.GetFriend()

	graduate1 := &Struct_graduate{
		Struct_people:Struct_people{
			Name:"123",
			Age:123,
		},
		Friend:"this",
	}
	fmt.Println(graduate1)

}